Two kinds of Life Tables can be distinguished: Period tables (Table du moment) which contain for each period (here a period is a calendar year), the mortality risks at different age ranges (here, we have one year ranges) for that very period; and Tables de génération which contain for a given birthyear, the mortality risks at which an individual born during that year has been exposed.
The life tables investigated in this lab are Table du moment. According to the document by Vallin and Meslé, building the life tables required ,decisions and doctoring.
Lexis diagrams
Lexis diagrams provide a graphical device that summarizes the construction of mortality quotients (and other rates in demography).
Code
birth_dates<-as_date("1999-01-01")+duration(sample(2*365, size=20, replace=T),units="day")death_dates<-as_date("2009-07-01")+duration(sample(3*365, size=20, replace=T),units="day")b_period<-as_date("2010-01-01")b_frame<-as_date(b_period-duration(1, units ="year"))b_age<-10Ltb_ld<-tibble(birth=birth_dates, death=death_dates)tb_ld|>ggplot()+geom_segment(aes(x=b_frame, xend=death, y=interval(birth, b_frame)/years(1), yend=interval(birth, death)/years(1)))+annotate(geom="rect", xmin=b_period, xmax=as_date(b_period+duration(1, units ="year")), ymin=b_age, ymax=b_age+1L, fill="grey", alpha=.5)+ylab("Age")+xlab("Time")+coord_cartesian(xlim=c(as_date(b_period-duration(6, units ="months")), as_date(b_period+duration(18, units ="months"))), ylim=c(b_age-.5, b_age+1.5))+labs( title="A Lexis diagram", subtitle ="for mortality quotient at Age 10 during Year 2010-11")
Each line represents the life line of an individual born during years 1999 and 2000 and deceased beetween mid 2009 and mid 2012. In order to compute the mortality quotient at age 10 for year 2010, we have to compute the relevant number of occurrences, that is the number of segments ending in the grey rectangle, and the sum of exposure times, which is proportional to the sum of the lengths of the segments crossing the grey rectangle.
Definitions can be obtained from www.lifeexpectancy.org. We translate it into mathematical (rather than demographic) language.
The mortality quotients define a probability distribution over \(\mathbb{N}\). This probability distribution is a construction that reflects the health situation in a population at a given time. This probability distribution does not describe the sequence of sanitary situations experienced by a cohort (people born during a specific year).
One works with a period, or current, life table (table du moment). This summarizes the mortality experience of persons across all ages in a short period, typically one year or three years. More precisely, the death probabilities \(q_x\) for every age \(x\) are computed for that short period, often using census information gathered at regular intervals. These \(q_x\)’s are then applied to a hypothetical cohort of \(100 000\) people over their life span to produce a life table.
The table above is not as readable as it should. Use package gt to get a more tunable outpout.
Reorder and filter the columns so that Age comes first (they identify rows), then qx, mx up to ex. You can use select or relocate, or both to do this. Note that Gender, Country, Year are constant in this tibble and need to be reported in the table header, but nowhere else.
Columns qx and mx (for mortality quotient and central death rate) should be dsplayed in scientific notation so that the fact that their range extends over several orders of magnitude shows up.
Columns lx, dx, Lx, Tx contain integer values.
Column ex (residual life expectancy) is a (fictional) decimal number of years
In the sequel, we denote by \(F_{t}\) the cumulative distribution function for year \(t\). We agree on \(\overline{F}_t = 1 - F_t\) and \(F_t(-1)=0\). Henceforth, \(\overline{F}\) is called the survival function.
qx
(age-specific) risk of death at age \(x\), or mortality quotient at given age \(x\) for given year \(t\).
About the definition of q_{t,x}
Defining and computing q_{t,x} does not boil down to knowing the number of people at age \(x\) at the beginning of ear \(t\) and knowing how many of them died during year \(t\). If we want to be rigorous, we need to know all life lines in the Lexis diagram, or equivalently, how many people at Age \(x\) were alive on each day of Year \(t\).
Mortality quotients define a probability distribution
For a given year \(t\), the sequence of mortality quotients define a survival function \(\overline{F}_t\) using the following recursion:
\[q_{t,x} = \frac{\overline{F}_t(x) - \overline{F}_t(x+1)}{\overline{F}_t(x)}\] with boundary condition \(\overline{F}_t(-1) =1\).
This artificial probability distribution is used to define and compute life expectancies.
\(q_{t,x}\) is the hazard rate of \(\overline{F}_t\) at age \(x\).
mx
central death rate at age \(x\) during year \(t\). This is connected with \(q_{t,x}\) by \[m_{t,x} = -\log(1- q_{t,x}) \,,\]
or equivalently \[q_{t,x} = 1 - \exp(-m_{t,x})\]
About central death rate
If we want to define a continuous probability distribution \(G\) over \([0,\infty)\) so that \(G\) and \(F\) coincide over integers and \(G\) has piecewise constant hazard rate, we can pick \(m_{t,x}\) as the piecewise constant hazard rate.
lx
the so-called survival function: the scaled proportion of persons alive at age \(x\). These values are computed recursively from the \(q_{t,x}\) values using the formula
\[l_t(x+1) = l_t(x) \times (1-q_{t,x}) \, ,\] with \(l_{t,0}\), the radix of the table, (arbitrarily) set to \(100000\). In the table lx is rounded to the next integer
Function \(l_{t,\cdot}\) and \(\overline{F}_t\) are connected by
\(d_{t,x} = q_{t,x} \times l_{t,x}\). The fictitious number of deaths occurring at age \(x\) during year \(t\). Again this is a rounded quantity.
Tx
Total number of person-years lived by the cohort from age \(x\) to \(x+1\). This is the sum of the years lived by the \(l_{t, x+1}\) persons who survive the interval, and the \(d_{t,x}\) persons who die during the interval. The former contribute exactly \(1\) year each, while the latter contribute, on average, approximately half a year, so that \(L_{t,x} = l_{t,x+1} + 0.5 \times d_{t,x}\). This approximation assumes that deaths occur, on average, half way in the age interval x to x+1. Such is satisfactory except at age 0 and the oldest age, where other approximations are often used.
Compare with the denominator in the definition of qx and its description using the Lexis diagram.
We will stick to a simplified vision \(L_{t,x}= l_{t,x+1}\)
ex:
Residual Life Expectancy at age \(x\) and year \(t\)
This is the expectation of \(X -x\) for a random variable \(X\) distributed according to \(\overline{F}_t\) conditionnally on the event \(\{ X \geq x \}\). That is \(e_{t,x}\) is the expectation of the probability distribution defined by \(\overline{F}_t(\cdot + x-1)/\overline{F}_t(x-1)\).
Plot mortality quotients (qx) against age using a logarithmic scale on the \(y\) axis. Countries are identified by aesthetics (shape, color, linetype).
Use facetting to plot qx of all countries at all ages for years 1950, 1960, …, 2010.
Use plotly to build an animated plot using Year for the frame aesthetics.
Abiding to the DRY principle, define a prototype ggplot (alternatively plotly) object.
The prototype will then be fed with different datasets and decorated and arranged for the different figures.
In 1948, NE and the USA exhibit comparable mortality quotients at all ages for the two genders, the USA looking like a more dangerous place for young adults. Spain lags behind, Italy and France showing up at intermediate positions.
By year 1962, SE has almost caught up the USA. Italy and Spain still have higher infant mortality while mortality quotients in the USA and France are almost identical at all ages for both genders. Mortality quotients attain a minimum around 10-12 for both genders. In Spain the minium central death rate has been divided by almost ten between 1948 and 1962.
If we dig further we observe that the shape of the male mortality quotients curve changes over time. In 1962, in the USA and France, mortality quotients exhibit a sharp increase between years 12 and 18, then remain almost constant between 20 and 30 and afterwards increase again. This pattern shows up in other countries but in a less spectacular way.
Twenty years afterwards, during years 1980-1985, death rates at age 0 have decreased at around \(1\%\) in all countries while it was \(7\%\) in Spain in 1948. The male central death curve exhibits a plateau between ages 20 and 30. Mortality quotients at this age look higher in France and the USA.
By year 2000, France is back amongst European countries (at least with respect to mortality quotients). Young adult mortality rates are higher in the USA than in Europe. This phenomenon became more pregnant during the last decade.
Question
Plot ratios between mortality quotients (qx) in European countries and mortality quotients in the USA in 1948.
Code
p<-with(params,(filter(eur_us_table, Year%%10==0)|>ggplot()+aes(x=Age, y=Ratio, frame=Year)+aes(linetype=Country, show.legend =FALSE)+aes(color=Area, show.legend =FALSE)+scale_y_log10()+scale_x_continuous(breaks =c(seq(0, 100, 10), 109))+geom_point(size=.1)+geom_smooth(method="loess", formula='y~ x', se=FALSE, span=.1, size=.1)+ylab("Ratio of mortality quotients with respect to US")+ggtitle(label =glue("European countries with respect to US,{year_p}-{year_e}"), subtitle ="Sweden consistently ahead")+facet_grid(rows =vars(Gender))))gp<-p|>ggplotly()gp
This animation reveals less than the preceding one since we just have ratios with respect to the USA. But the patterns followed by European societies emerge in a more transparent way. The divide between northern and southern Europe at the onset of the period is even more visible. The ratios are important across the continent: there is a factor of 10 between spanish and swedish infant mortality rates. But the ratios at ages 50 and above tend to be similar. By the early 60s, the gap between southern and northern Europe has shrinked. By now, the ratios between mortality quotients tend to be within a factor of 2 across all ages, and even less at ages 50 and above.
Death rates evolution since WW II
Question
Plot mortality quotients (column qx) for both genders as a function of Age for years 1946, 1956, ... up to 2016 . Use aesthetics to distinguish years. You will need to categorize the Year column (forcats:: may be helpful).
Facet by Gender and Country
Pay attention to axes labels, to legends. Assess logarithmic scales.
Code
p_3<-(p%+%filter(life_table,Year%in%post_ww_II, Gender!="Both",Age<90,Country%in%c('Spain', 'USA'))+labs(title="Mortality quotient per Age", subtitle ="Post WW II"))
Code
p_3|>ggplotly()
Question
Write a function ratio_mortality_rates with signature function(df, reference_year=1946, target_years=seq(1946, 2016, 10)) that takes as input:
a dataframe with the same schema as life_table,
a reference year ref_year and
a sequence of years target_years
and that returns a dataframe with schema:
Column Name
Column Type
Year
integer
Age
integer
mx
double
mx.ref_year
double
Country
factor
Gender
factor
where (Country, Year, Age, Gender) serves as a primary key, mx denotes the central death rate at Age for Year and Gender in Country whereas mx_ref_year denotes central death rate at Age for argument reference_year in Country for Gender.
Draw plots displaying the ratio \(q_{x,t}/q_{x, 1946}\) for ages \(x \in 1, \ldots, 90\) and year \(t\) for \(t \in 1946, \ldots, 2013\) where \(q_{x,t}\) is the mortality quotient at age \(x\) during year \(t\).
Handle both genders and all countries
One properly facetted plot is enough.
Code
geom_smooth_line<-geom_smooth(method="loess", formula =y~x, se=FALSE, size =.2, span=.1)
Code
q<-df_ratios|>ggplot()+aes(x=Age, y=qx.x/qx.y)+geom_smooth_line+scale_y_log10()q1<-q+aes(linetype=as_factor(Year), col=as_factor(Year))+ylab("Ratio of mortality rates, reference Year 1946")+labs(linetype="Year", col="Year")+scale_colour_brewer()+theme(legend.position ="none")+facet_grid( rows =vars(Country), cols =vars(Gender), scales ="free_y")q1